<template>
  <div class="relative group">
    <button class="flex items-center gap-3">
      <el-avatar
        :size="40"
        :src="userInfo.avatar"
        class="rounded-xl ring-2 ring-primary/20"
      />
      <el-icon class="text-gray-400 transition-transform group-hover:rotate-180">
        <ArrowDown />
      </el-icon>
    </button>
    <div
      class="absolute top-full right-0 mt-1 w-64 bg-white rounded-xl shadow-xl border border-gray-100 opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all py-3"
    >
      <!-- 用户信息部分 -->
      <div class="px-4 py-2 border-b border-gray-100">
        <div class="flex items-center gap-3 mb-2">
          <el-avatar
            :size="48"
            :src="userInfo.avatar"
            class="rounded-xl ring-2 ring-primary/20"
          />
          <div>
            <h4 class="font-semibold text-gray-900">{{ userInfo.name }}</h4>
            <p class="text-xs text-gray-500">{{ userInfo.title }}</p>
          </div>
        </div>
        <div class="flex items-center gap-2 mt-3">
          <el-tag
            v-for="tag in userInfo.tags"
            :key="tag.text"
            :type="tag.type"
            size="small"
            class="rounded-full"
          >
            {{ tag.text }}
          </el-tag>
        </div>
      </div>
      <!-- 菜单列表 -->
      <div class="py-2">
        <a
          v-for="item in menuItems"
          :key="item.text"
          href="#"
          :class="[
            'flex items-center gap-3 px-4 py-2 text-gray-600 transition-colors',
            item.hoverColor || 'hover:text-primary hover:bg-primary/5'
          ]"
        >
          <span
            :class="[
              'flex items-center justify-center w-8 h-8 rounded-lg',
              item.iconBg,
              item.iconColor,
            ]"
          >
            <el-icon class="text-sm">
              <component :is="item.icon" />
            </el-icon>
          </span>
          <span>{{ item.text }}</span>
        </a>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import {
  User,
  Setting,
  SwitchButton
} from '@element-plus/icons-vue'

const userInfo = ref({
  avatar: 'https://ai-public.mastergo.com/ai/img_res/fb169420bd573d8f2f4bdfce9434266f.jpg',
  name: '陈思远',
  title: '全栈开发工程师',
  tags: [
    { text: '技术专家', type: 'primary' },
    { text: '活跃作者', type: 'success' }
  ]
})

const menuItems = ref([
  {
    icon: User,
    text: '个人中心',
    iconBg: 'bg-primary/10',
    iconColor: 'text-primary'
  },
  {
    icon: Setting,
    text: '设置',
    iconBg: 'bg-green-500/10',
    iconColor: 'text-green-500'
  },
  {
    icon: SwitchButton,
    text: '退出登录',
    iconBg: 'bg-red-500/10',
    iconColor: 'text-red-500',
    hoverColor: 'hover:text-red-500 hover:bg-red-50'
  }
])
</script>

<style scoped>
.group:hover .el-icon {
  transform: rotate(180deg);
}

:deep(.el-dropdown-item) {
  padding: 0;
}

:deep(.el-dropdown-item:not(.is-disabled):hover) {
  background-color: transparent;
}

:deep(.el-tag) {
  border: none;
}

:deep(.el-tag--primary) {
  background-color: rgba(59, 130, 246, 0.1);
  color: rgb(59, 130, 246);
}

:deep(.el-tag--success) {
  background-color: rgba(34, 197, 94, 0.1);
  color: rgb(34, 197, 94);
}
</style>